package com.example.constants.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 证件枚举类
 * 
 * @author 李隆铨
 */
public enum CertificateTypeEnum {
    /** 身份证 */
    I("身份证", "001"),
    /** 港澳通行证 */
    T("港澳通行证", "002"),
    /** 护照 */
    P("护照", "003");

    private String name;
    private String code;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    private CertificateTypeEnum(String name, String code) {
        this.name = name;
        this.code = code;
    }

    public static String getCode(String name) throws Exception {
        if (StrUtil.isBlank(name)) {
            throw new Exception("传入值有问题!!");
        }
        for (CertificateTypeEnum certificateTypeEnum : CertificateTypeEnum.values()) {
            if (StrUtil.equals(name, certificateTypeEnum.getName())) {
                return certificateTypeEnum.getCode();
            }
        }
        return null;

    }

    public static String getName(String code) throws Exception {
        if (StrUtil.isBlank(code)) {
            throw new Exception("传入值有问题!!");
        }
        for (CertificateTypeEnum certificateTypeEnum : CertificateTypeEnum.values()) {
            if (StrUtil.equals(code, certificateTypeEnum.getCode())) {
                return certificateTypeEnum.getName();
            }
        }
        return null;
    }

}
